package com.atguigu.distributed.lock.leecode;

import java.util.LinkedHashMap;
import java.util.Map;

public class LRULinkedMap<K, V> extends LinkedHashMap<K, V> {
    private int capacity;
    public LRULinkedMap(int capacity) {
        super(capacity,0.75F,true);
        this.capacity = capacity;
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
        return super.size()>capacity;
    }
    public static void main(String[] args){
        LRULinkedMap<Object, Object> map = new LRULinkedMap<>(3);
        map.put(1,"a");
        map.put(2,"b");
        map.put(3,"c");
        System.out.println(map.keySet());
        map.put(4, "d");
        System.out.println(map.keySet());
    }
}
